package com.huawei.crm.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.huawei.crm.domain.Systemdictionaryitem;
import com.huawei.crm.mapper.SystemdictionaryitemMapper;
import com.huawei.crm.query.QueryObject;
import com.huawei.crm.service.ISystemdictionaryitemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class SystemdictionaryitemServiceImpl implements ISystemdictionaryitemService {

    @Autowired
    private SystemdictionaryitemMapper mapper;

    public void saveOrUpdate(Systemdictionaryitem dic) {
        if (dic.getId() == null) {
            mapper.insert(dic);
        } else {
            mapper.updateByPrimaryKey(dic);
        }

    }

    public void delete(Long id)    {
        mapper.deleteByPrimaryKey(id);
    }

    public Systemdictionaryitem get(Long id) {
        return mapper.selectPrimaryKey(id);
    }

    @Transactional(readOnly = true)
    public List<Systemdictionaryitem> listAll() {
        return mapper.selectAll();
    }

    @Transactional(readOnly = true)
    public PageInfo<Systemdictionaryitem> query(QueryObject qo) {
        // 告诉mybatis需要去哪里拼接sql
        PageHelper.startPage(qo.getCurrentPage(), qo.getPageSize(),"sequence DESC");
        List<Systemdictionaryitem> list = mapper.selectForList(qo);
        return new PageInfo<>(list);
    }

    @Transactional(readOnly = true)
    public List<Systemdictionaryitem> listItemsByDictionarySn(String sn) {
        return mapper.selectItemsByDictionarySn(sn);
    }

}
